package com.tensquare.search.controller;

import com.tensquare.search.pojo.Article;
import com.tensquare.search.service.ArticleService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by WF on 2020/10/22 11:21
 */
@RestController
@RequestMapping("article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    //1. 添加到索引库
    @PostMapping
    public Result add(@RequestBody Article article){
        articleService.add(article);
        return new Result(StatusCode.OK,true,"添加成功！");
    }

    //2.根据标题或内容进行文章的搜索
    @GetMapping("/search/{keywords}/{page}/{size}")
    public Result search(@PathVariable String keywords,@PathVariable int page,@PathVariable int size){
        PageResult<Article> articlePageResult = articleService.search(keywords,page,size);
        return new Result(StatusCode.OK,true,"查询成功！",articlePageResult);
    }
}
